<div class="main-wrap">
	<section id="list-view-2" class="badge-list-view-element variant-right">
	<?php if(!empty($data)): ?>
		<?php $cate = $this->config->item('categories'); ?>
        <?php $permalink = '';$arrUri = array();$i = 1;$indicator = '';$shareLink = ''; ?>
	 	<?php foreach($data as $post): ?>
        <?php $post->post_title = strip_tags($post->post_title); $permalink = permalink(array('text' => $post->post_title, 'id' => $post->id));$shareLink = urlencode($permalink); ?>
        <?php
        $arrUri[] = $permalink;
        ?>

		<div class="badge-entry-collection" data-id="<?php echo $post->id ?>">
			<!--begin article-->
			<article data-entry-id="<?php echo $post->id ?>" data-entry-url="<?php echo $permalink ?>" id="jsid-entry-entity-<?php echo $post->id ?>" class="badge-entry-container badge-entry-entity">
				<header>
					<h2 class="badge-item-title">
						<a class="badge-evt badge-track" href="<?php echo $permalink ?>" target="_blank">
						<?php echo $post->post_title ?>
						</a>
					</h2>
					<!--
					<div class="float-vote-shadow badge-entry-sticky-shadow">
						<div class="badge-entry-sticky">
							<div class="float-vote-2">
								<ul class="badge-item-vote-container  ">
									<li>
										<a class="badge-item-vote-up display good" href="javascript:void(0);">
										<span class="icon"></span>
										</a>
									</li>
									<li class="count"><span id="love-count-<?php echo $post->id ?>" class="badge-item-love-count">
										<div class="fb-like" data-href="<?php echo $permalink; ?>" data-width="The pixel width of the plugin" data-height="The pixel height of the plugin" data-colorscheme="light" data-layout="box_count" data-action="like" data-show-faces="false" data-send="false"></div>
									</span></li>
									<li>
										<a class="badge-item-vote-down display meh" href="javascript:void(0);">
										<span class="icon"></span>
										</a>
									</li>
								</ul>
							</div>
						</div>
					</div>
					-->
				</header>
				<?php if($post->item_type == 'video'){
					$indicator = 'video-post';
                }
                elseif($post->item_type == 'gif'){
                	$indicator = 'gif-post';
                }
                else{
                	$indicator = '';
                }
                ?>
				<div class="badge-post-container post-container <?php echo $indicator; ?>">
					<a href="javascript:void(0)" class="badge-track badge-track-no-follow">
						<img class="badge-item-img" src="<?php echo getThumbnail('460x460', $post->post_image) ?>" alt="<?php echo $post->post_title ?>">
						<?php if($post->item_type == 'gif' || $post->item_type == 'video'):?>
						<span class="play">Play</span>
						<?php endif; ?>
						<?php if($indicator == 'gif-post'): ?>
						<div class="badge-animated-container-animated hide">
				            <img alt="<?php echo $post->post_title ?>" src="<?php echo getImage($post->post_image) ?>" class="badge-item-animated-img">
				        </div>
					    <?php else: ?>
					    	<div class="badge-animated-container-animated hide">
					            <iframe width="460" height="345" src="//www.youtube.com/embed/<?php echo youtubeVideoExtractor($post->video_code) ?>?rel=0" frameborder="0" allowfullscreen></iframe>
					        </div>
					    <?php endif; ?>
					</a>
				</div>
				<div class="post-afterbar in-list-view">
					<div class="share">
						<div class="share-count"><p>Chia sẻ<br />niềm vui</p></div>
						<ul>
							<li><a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo $shareLink; ?>" title="Chia sẻ lên facebook" target="_blank" class="badge-facebook-share badge-evt badge-track facebook"><span>Share on Facebook</span></a></li>
				            <li><a title="Đăng lên Google+" target="_blank" href="https://plus.google.com/share?url=<?php echo $shareLink; ?>" class="badge-gplus-share badge-evt badge-track google-plus">Share on Google+</a> </li>
				            <li><a title="Gửi lên Twitter" href="https://twitter.com/share?url=<?php echo $shareLink; ?>" target="_blank" class="badge-twitter-share badge-evt badge-track twitter">Tweet this</a> </li>
				            <li><a title="Pin lên Pinterest" target="_blank" href="//www.pinterest.com/pin/create/button/?url=<?php echo $shareLink; ?>&media=<?php echo urlencode(getThumbnail('460x460', $post->post_image)); ?>" class="badge-pinterest-share badge-evt badge-track pinterest">Pin it</a> </li>
						</ul>
					</div>
				</div>
			</article>
		</div>
			<?php $i++;endforeach; ?>
		<?php endif; ?>
		
		<input type="hidden" id="last-entry" value="">
		<div class="loading">
			<a class="btn badge-load-more-post" href="<?php echo BASE_URL . '/page/' . (HOME_LIMIT + (int)$page) . '-0' ?>">Xem thêm</a>
		</div>
	</section>
</div>
<script type="text/javascript">
var page = <?php echo (int)$page; ?>;
var _LOAD_MORE = $('.badge-load-more-post');
var _LAST_ENTRY = $('#last-entry');
hasReach = false;
$(window).scroll(function() {
	var lastItem = $('.badge-entry-collection:last');
    if($(window).scrollTop() > parseInt(lastItem.offset().top - 400)) {
       if(hasReach) return;
       hasReach = true;
       totalItem = $('.badge-entry-collection').size();
       offset = totalItem+page;
       if(totalItem >= <?php echo HOME_LIMIT*LIMIT_LOAD_MORE_PAGE ?>){
        _LOAD_MORE.show();
        LAST_ID = lastItem.data('id');
        _LOAD_MORE.attr('href', BASE_URL+'/page/'+offset+'-'+_LAST_ENTRY.val());
       }
       else{
           _LOAD_MORE.html('Đang tải thêm bài..');
           $.ajax({
            url: "<?php echo BASE_URL.'/ajax/loadmore' ?>",
            type: 'POST',
            dataType:'json',
            data: {'offset':offset},
            }).done(function(data){
            	_LOAD_MORE.html('Xem thêm');
                $(lastItem).after(data.html);
                _LAST_ENTRY.val(data.lastid);
                hasReach = false;
                _LOAD_MORE.attr('href', BASE_URL+'/page/'+ parseInt($('.badge-entry-collection').size() + page) +'-'+data.lastid);
                if(data.html == ''){
                	hasReach = true;
                }
                _float_summary();
            });
        }
    }
});
</script>